package com.itqf.ipmsys.utils;




import com.itqf.ipmsys.entity.Admin;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * 用于Shiro权限支持服务
 * 	1、获取认证对象
 * 	2、获取认证对象的名称
 * 	3、获取认证对象的id
 * @author zhaojian
 *
 */
public class AuthSupport {

	public static final Object BRAND_ROLE_NAME = "品牌制造商";

	public static final Object SUPER_ROLE_NAME = "超级管理员";
	

	/**
	 * 获取Shiro中存储的用户对象
	 * @return
	 */
	public static Admin currentUser() {
		Admin admin = null;
		Subject currentUser = SecurityUtils.getSubject();
		if (currentUser != null) {
			admin = (Admin) currentUser.getPrincipal();
		}
		return admin;
	}
	
	/**
	 * 获取Shiro中存储的用户的用户名
	 * @return
	 */
	public static String userName() {
		String userName = null;

		Admin currentUser = currentUser();

		if (currentUser != null) {
			userName = currentUser.getAccount();
		}
		return userName;
	}
	
	/**
	 * 获取Shiro中存储的用户的用户id
	 * @return
	 */
	public static Integer adminId() {
		Integer adminId = null;
		Admin currentUser = currentUser();
		if (currentUser != null) {
			adminId = currentUser.getId();
		}
		return adminId;
	}
}
